import { createApp } from 'vue'
import App from './App.vue'
import router from "./router";
import store from "./stores"
import Particles from "@tsparticles/vue3"
import { loadSlim } from "@tsparticles/slim";
import * as utils from "./assets/common/utils"
import echarts from "./assets/common/echarts"
import axios from "./assets/common/request"
import { IMG_URL } from './assets/common/config'

import ElementPlus from 'element-plus'
import { ElMessage } from 'element-plus'
import 'element-plus/dist/index.css'

import 'uno.css'

const app = createApp(App);


// 全局导入elementUI 图标
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

// 自定义指令
import directive from './directive'
directive(app)

// 读取 public 下的 version.json 文件，记录版本信息
fetch(`version.json?time=${Date.now()}`).then(response => response.json())
    .then(data => {
        const version = data.version
        if (version) {
            localStorage.setItem('__APP_VERSION__', version)
        }
    })
    .catch(error => {
        console.log(error);
    })

const pagePath = window.location.host;
// console.log('当前页面路径mian:', pagePath);
// 全局挂载
app.config.globalProperties.$util = utils;
app.config.globalProperties.$echarts = echarts
// app.config.globalProperties.imgUrl = IMG_URL
app.config.globalProperties.imgUrl = "https://"+pagePath+'/api/v1/resources'
app.config.globalProperties.hostUrl = "https://"+pagePath+'/api/v1/'
app.config.globalProperties.$axios = axios;

app.provide('$axios', axios)
app.provide('$message', ElMessage)
app.provide('imgUrl', IMG_URL)

app.use(ElementPlus)
app.use(router).use(store).use(Particles, {
    init: async engine => {
        await loadSlim(engine);
    }
}).mount("#app")
